package com.ttms.dao.impl;

import com.ttms.dao.SeatDao;
import com.ttms.pojo.Seat;

import java.util.List;

public class SeatDaoImpl extends BaseDao implements SeatDao {
    @Override
    public int addSeat(Seat seat) {
        String sql = "insert into seat(`studio_id` ,`seat_row`,`seat_column`,`seat_status`) values(?,?,?,?)";
        return update(sql, seat.getStudio_id(),seat.getSeat_row(),seat.getSeat_column(),seat.getSeat_status());
    }

    @Override
    public int updateSeatStatus(Seat seat) {
        String sql = "update seat set `seat_status` = ? where studio_id=? and seat_row=? and seat_column=?";
        return update(sql,seat.getSeat_status(),seat.getStudio_id(),seat.getSeat_row(),seat.getSeat_column());
    }

    @Override
    public List<Seat> findSeatByStudioId(Integer studio_id) {
        String sql="select * from seat where studio_id = ?";
        return queryForList(Seat.class, sql, studio_id);
    }


    @Override
    public Seat findSeatByRowAndCol(Integer studio_id, Integer row, Integer col) {
        String sql="select * from seat where studio_id = ?  and `seat_row`=? and `seat_column`=?";
        return queryForOne(Seat.class, sql, studio_id,row,col);
    }

    @Override
    public Seat findSeat(Integer seat_id) {
        String sql = "select * from seat where seat_id = ?";
        return queryForOne(Seat.class, sql,seat_id);
    }

}
